package com.microsoft;

import com.alibaba.fastjson.JSONObject;
import com.service.ParseAuId;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.net.URI;

/**
 * Created by weiaquarius on 16/5/4.
 */
public class AuId {
    public void exprAuId(){
        HttpClient httpclient = HttpClients.createDefault();

        try
        {
            URIBuilder builder = new URIBuilder("https://oxfordhk.azure-api.net/academic/v1.0/evaluate");

            builder.setParameter("expr", "Composite(AA.AuId=700773976)");
            builder.setParameter("model", "latest");
            builder.setParameter("attributes", "Id,Ti,CC,RId,F.FId,AA.AuId,AA.AfId,J.JId,C.CId");
            builder.setParameter("count", "40");
            builder.setParameter("offset", "0");
            builder.setParameter("subscription-key", "f7cc29509a8443c5b3a5e56b0e38b5a6");

            URI uri = builder.build();
            HttpGet request = new HttpGet(uri);
            //request.setHeader("Ocp-Apim-Subscription-Key", "9c42c0fbb6b34940834a3ab119a442f5");


            // Request body
            //StringEntity reqEntity = new StringEntity("{body}");
            //request.setEntity(reqEntity);
            //request.set

            HttpResponse response = httpclient.execute(request);
            HttpEntity entity = response.getEntity();

            if (entity != null)
            {//json解析过程
                String string = EntityUtils.toString(entity);
                ParseAuId parseAuId = new ParseAuId();
                parseAuId.parse(JSONObject.parseObject(string));
                System.out.println(JSONObject.toJSON(string));
            }
        }
        catch (Exception e)
        {
            System.out.println(e.getMessage());
        }
    }
}
